package org.discala.samples.complex.recipegenerator

import scala.util.Random
import org.discala.samples.complex.domain.MealType._
import org.discala.samples.complex.domain.PreparationMethod._

/**
 * @author Chris Turner
 */
private[recipegenerator] trait MethodSelectorComponent {

  val methodSelector: () => MethodSelector

  class RandomMethodSelector extends MethodSelector {

    private[this] val random = new Random

    def selectMethod(mealType: MealType) = {
      mealType match {
        case Hot => {
          random.synchronized {
            random.nextInt(5) match {
              case 0 => Bake
              case 1 => Grill
              case 2 => Boil
              case 3 => Fry
              case 4 => Toast
              case _ => Bake
            }
          }
        }
        case _ => {
          random.synchronized {
            random.nextInt(3) match {
              case 0 => Stand
              case 1 => Chill
              case 2 => Freeze
              case _ => Stand
            }
          }
        }
      }
    }
  }
}
